﻿using Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class AlarmDataService
    {
        /// <summary>
        /// 插入信息
        /// </summary>
        /// <param name="alarmData"></param>
        /// <returns></returns>
        /// 
        public bool InsertAlarmData(AlarmData alarmData)
        {
            //sql语句
            string sqlString = "insert into AlarmData(AlarmTime,AlarmName,AlarmStatus) values(@AlarmTime,@AlarmName,@AlarmStatus)";

            //sql参数
            SQLiteParameter[] parm = new SQLiteParameter[]
            {
                new SQLiteParameter("@AlarmTime",alarmData.AlarmTime),
                new SQLiteParameter("@AlarmName",alarmData.AlarmName),
                new SQLiteParameter("@AlarmStatus",alarmData.AlarmStatus)
            };

            //返回操作结果
            return SQLiteHelper.ExecuteNonQuery(sqlString, parm) == 1;
        }

        /// <summary>
        /// 通过时间段查询信息
        /// </summary>
        /// <param name="alarmData"></param>
        /// <returns></returns>
        public DataTable QueryAlarmData(string start, string end)
        {
            //降序
            string sqlString = "select AlarmTime,AlarmName,AlarmStatus from AlarmData where AlarmTime between @start and @end order by AlarmTime DESC";

            SQLiteParameter[] parm = new SQLiteParameter[]
            {
                new SQLiteParameter("@start",start),
                new SQLiteParameter("@end",end)
            };

            //接收表数据
            return SQLiteHelper.ExecuteQuery(sqlString, parm);
        }
    }
}
